/**
 * Class $$.util.Task
 * The class for create delayed task
 * 
 * @type class
 * @author TCL
 * @version 1
 * @since 1
 */

$$.util.Task = function(interval){
	var me = this
		,id;
		
	interval = 0 <= interval? interval : 1000;
		
	$$.put(me, {
		/**
		 * set delayed time
		 * @param int i the miliseconds for delayed
		 * @return $$.util.Task this
		 */
		delay: function(i){
			interval = i;
			return me;
		}
	
		/**
		 * start the task
		 * @param Function fn
		 * @param object scope
		 * @param array args
		 * @return $$.util.Task
		 */
		,start: function(fn, scope, args){
			me.cancel();
			id = fn.create(scope, args, [], interval)();
			return me;
		}
		
		/**
		 * cancel the task
		 * @return $$.util.Task
		 */
		,cancel: function(){
			clearTimeout(id);
			return me;	
		}		
	});
};